#include <iostream>
using namespace std;


bool duplicate(int numbers[], int length, int* duplication) {
    if(numbers==NULL||length<=1||duplication==NULL)
    {
        return false;

    }
    int i=0;
    for(i=0;i<length;i++)
    {
        if(numbers[i]<0||numbers[i]>=length)    
        {
            return false;
        }

    }
    int *buffer=new int[length];
    for(i=0;i<length;i++)
    {
        buffer[i]=numbers[i];
    }
    for(i=0;i<length;i++)
    {
        if(buffer[numbers[i]]>=length)
        {
            *duplication=buffer[numbers[i]]-length;
            return true;

        }
        else
        {
                buffer[numbers[i]]+=length;
        }

    }
    return false;

}

int main()
{
    int arr[6]={5,0,2,3,1,4};
    int tmp=0;
    bool test=duplicate(arr,6,&tmp);
    if(test)
    {
        cout<<tmp<<endl;
    }
    else
    {
        cout<<"error"<<endl;
    }
}
